<?php
include 'db-config.php';
//$xml = simplexml_load_file("global_to_do_category_listing_for_feed.xml");
$xml = simplexml_load_file("http://globaltodo.com/xmlcontact/admin/global_to_do_category_listing_for_feed.xml");
$xmlarray = array(); 
function xmlToArray($input, $callback = null, $recurse = false) {
	 $data = ((!$recurse) && is_string($input))? simplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA): $input;
	 if ($data instanceof SimpleXMLElement) $data = (array) $data;
	 if (is_array($data)) foreach ($data as &$item) $item = xmlToArray($item, $callback, true);
	 return (!is_array($data) && is_callable($callback))? call_user_func($callback, $data): $data;
	}

$xmlarray = xmlToArray($xml);

//print_r($xmlarray);
$arrIdSlNo = array();

$count=0;
if(is_array($xmlarray) && count($xmlarray)>0)
{
	mysql_query("TRUNCATE table tbl_globaltodo_listings");
}
foreach($xmlarray as $key=>$val)
{
	
	if($key=="sl_no")
	{
		
		foreach ($val as $keySl=>$valSl)
		{
			$sqlInsert ="INSERT INTO tbl_globaltodo_listings (id) VALUES ($valSl)";
			array_push($arrIdSlNo,$valSl);
			mysql_query($sqlInsert);
		}
	}
}
foreach($xmlarray as $key=>$val)
{
		$count=0;
		foreach ($val as $keySl=>$valSl)
		{
			if($key=="id")
				$key ="unique_id";
			else if ($key=="theme")
				$key ="category";
			else if ($key=="business_logo")
				$valSl = "http://www.globaltodo.com/xmlcontact/".$valSl;
			else if ($key=="image_1")
				$valSl = "http://www.globaltodo.com/xmlcontact/".$valSl;
			else if ($key=="image_2")
				$valSl = "http://www.globaltodo.com/xmlcontact/".$valSl;
			else if ($key=="image_3")
				$valSl = "http://www.globaltodo.com/xmlcontact/".$valSl;
			else if ($key=="image_4")
				$valSl = "http://www.globaltodo.com/xmlcontact/".$valSl;
			else if ($key=="barcode_image")
				$valSl = "http://www.globaltodo.com/xmlcontact/".$valSl;
				
			if(is_array($valSl) && (count($valSl)==0))
			{
				$valSl='';
			}
			$sql ="UPDATE tbl_globaltodo_listings SET ".$key."='".addslashes($valSl)."' WHERE id=".$arrIdSlNo[$count]."";
			$count++;
			mysql_query($sql);
			
		}
	}


?> 